package org.scboy.common.dynamic.node.objectNode;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.dynamic.node.BaseNode;
import org.scboy.utils.entitys.coobi.Model;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;

@ScriptNode(value="CREATE_BOOLEAN",isData = true)
public class CreateBooleanNode extends BaseNode {

	private String paramName="";
	private String paramValue="";
	
	@Override
	public void create(JSONObject object) {
		paramName=object.getStr("paramName");
		paramValue=object.getStr("paramValue");
	}

	@Override
	public Object run() {
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		if(StrUtil.isEmpty(paramName)) {
			throw new RuntimeException(getNodeName()+"为数据节点，没有设置参数名称。");
		}

		if(StrUtil.isEmpty(paramValue)) {
			throw new RuntimeException(getNodeName()+"为数据节点，未定义变量值。");
		}
		
		boolean value=Convert.toBool(paramValue);
		this.setData("entity", Model.create().add(paramName, value));
		this.setData("boolean", value);
		
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
		}
		
		return null;
	}
	
}
